home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillips / boole.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  7.0 KB  |  248 lines

  1. #include "cips.h"
  2.  
  3. and_image(in1_name, in2_name, out_name,
  4.           the_image, out_image,
  5.           il1, ie1, ll1, le1,
  6.           il2, ie2, ll2, le2,
  7.           il3, ie3, ll3, le3)
  8.    char   in1_name[], in2_name[], out_name[];
  9.    int    il1, ie1, ll1, le1,
  10.           il2, ie2, ll2, le2,
  11.           il3, ie3, ll3, le3;
  12.    short  the_image[ROWS][COLS],
  13.           out_image[ROWS][COLS];
  14. {
  15.    int    i, j, length, width;
  16.    struct tiff_header_struct image_header;
  17.  
  18.    create_file_if_needed(in1_name, out_name, out_image);
  19.  
  20.    read_tiff_image(in1_name, the_image,
  21.                    il1, ie1, ll1, le1);
  22.    read_tiff_image(in2_name, out_image,
  23.                    il2, ie2, ll2, le2);
  24.  
  25.    for(i=0; i<ROWS; i++){
  26.       if ( (i%10) == 0) printf(" %d", i);
  27.       for(j=0; j<COLS; j++){
  28.          if( the_image[i][j] != 0   &&
  29.              out_image[i][j] != 0)
  30.              out_image[i][j] = the_image[i][j];
  31.          else
  32.              out_image[i][j] = 0;
  33.       }  /* ends loop over j */
  34.    }  /* ends loop over i */
  35.  
  36.    write_array_into_tiff_image(out_name, out_image,
  37.                                il3, ie3, ll3, le3);
  38.  
  39. } /* ends and_image */
  40.  
  41. /*************************************************/
  42.  
  43. or_image(in1_name, in2_name, out_name,
  44.          the_image, out_image,
  45.          il1, ie1, ll1, le1,
  46.          il2, ie2, ll2, le2,
  47.          il3, ie3, ll3, le3)
  48.    char  in1_name[], in2_name[], out_name[];
  49.    int   il1, ie1, ll1, le1,
  50.          il2, ie2, ll2, le2,
  51.          il3, ie3, ll3, le3;
  52.    short the_image[ROWS][COLS],
  53.          out_image[ROWS][COLS];
  54. {
  55.    int    i, j, length, width;
  56.    struct tiff_header_struct image_header;
  57.  
  58.    create_file_if_needed(in1_name, out_name, out_image);
  59.  
  60.    read_tiff_image(in1_name, the_image,
  61.                    il1, ie1, ll1, le1);
  62.    read_tiff_image(in2_name, out_image,
  63.                    il2, ie2, ll2, le2);
  64.  
  65.    for(i=0; i<ROWS; i++){
  66.       if ( (i%10) == 0) printf(" %d", i);
  67.       for(j=0; j<COLS; j++){
  68.          if( the_image[i][j] != 0   ||
  69.              out_image[i][j] != 0){
  70.              if(the_image[i][j] != 0)
  71.                 out_image[i][j] = the_image[i][j];
  72.              else
  73.                 out_image[i][j] = out_image[i][j];
  74.          }
  75.          else
  76.              out_image[i][j] = 0;
  77.       }  /* ends loop over j */
  78.    }  /* ends loop over i */
  79.    write_array_into_tiff_image(out_name, out_image,
  80.                                il3, ie3, ll3, le3);
  81.  
  82. } /* ends or_image */
  83.  
  84. /*************************************************/
  85.  
  86. xor_image(in1_name, in2_name, out_name,
  87.           the_image, out_image,
  88.           il1, ie1, ll1, le1,
  89.           il2, ie2, ll2, le2,
  90.           il3, ie3, ll3, le3)
  91.    char   in1_name[], in2_name[], out_name[];
  92.    int    il1, ie1, ll1, le1,
  93.           il2, ie2, ll2, le2,
  94.           il3, ie3, ll3, le3;
  95.    short  the_image[ROWS][COLS],
  96.           out_image[ROWS][COLS];
  97. {
  98.    int    i, j, length, width;
  99.    short  answer;
  100.    struct tiff_header_struct image_header;
  101.  
  102.    create_file_if_needed(in1_name, out_name, out_image);
  103.  
  104.    read_tiff_image(in1_name, the_image,
  105.                    il1, ie1, ll1, le1);
  106.    read_tiff_image(in2_name, out_image,
  107.                    il2, ie2, ll2, le2);
  108.  
  109.    for(i=0; i<ROWS; i++){
  110.       if ( (i%10) == 0) printf(" %d", i);
  111.       for(j=0; j<COLS; j++){
  112.          if( (the_image[i][j] != 0 &&
  113.               out_image[i][j] == 0))
  114.              answer = the_image[i][j];
  115.          if( (the_image[i][j] == 0 &&
  116.               out_image[i][j] != 0))
  117.              answer = out_image[i][j];
  118.          if( (the_image[i][j] == 0 &&
  119.               out_image[i][j] == 0))
  120.              answer = 0;
  121.          if( (the_image[i][j] != 0 &&
  122.               out_image[i][j] != 0))
  123.              answer = 0;
  124.          out_image[i][j] = answer;
  125.       }  /* ends loop over j */
  126.    }  /* ends loop over i */
  127.  
  128.    write_array_into_tiff_image(out_name, out_image,
  129.                                il3, ie3, ll3, le3);
  130.  
  131. } /* ends xor_image */
  132.  
  133. /*****************************************************/
  134.  
  135. nand_image(in1_name, in2_name, out_name,
  136.            the_image, out_image,
  137.            il1, ie1, ll1, le1,
  138.            il2, ie2, ll2, le2,
  139.            il3, ie3, ll3, le3, value)
  140.    char    in1_name[], in2_name[], out_name[];
  141.    int     il1, ie1, ll1, le1,
  142.            il2, ie2, ll2, le2,
  143.            il3, ie3, ll3, le3;
  144.    short   the_image[ROWS][COLS],
  145.            out_image[ROWS][COLS], value;
  146. {
  147.    int    i, j, length, width;
  148.    struct tiff_header_struct image_header;
  149.  
  150.    create_file_if_needed(in1_name, out_name, out_image);
  151.  
  152.    read_tiff_image(in1_name, the_image,
  153.                    il1, ie1, ll1, le1);
  154.    read_tiff_image(in2_name, out_image,
  155.                    il2, ie2, ll2, le2);
  156.  
  157.    for(i=0; i<ROWS; i++){
  158.       if ( (i%10) == 0) printf(" %d", i);
  159.       for(j=0; j<COLS; j++){
  160.          if( the_image[i][j] != 0   &&
  161.              out_image[i][j] != 0)
  162.              out_image[i][j] = 0;
  163.          else
  164.              out_image[i][j] = value;
  165.       }  /* ends loop over j */
  166.    }  /* ends loop over i */
  167.  
  168.    write_array_into_tiff_image(out_name, out_image,
  169.                                il3, ie3, ll3, le3);
  170.  
  171. } /* ends nand_image */
  172.  
  173. /******************************************************/
  174.  
  175. nor_image(in1_name, in2_name, out_name,
  176.           the_image, out_image,
  177.           il1, ie1, ll1, le1,
  178.           il2, ie2, ll2, le2,
  179.           il3, ie3, ll3, le3, value)
  180.    char   in1_name[], in2_name[], out_name[];
  181.    int    il1, ie1, ll1, le1,
  182.           il2, ie2, ll2, le2,
  183.           il3, ie3, ll3, le3;
  184.    short  the_image[ROWS][COLS],
  185.           out_image[ROWS][COLS], value;
  186. {
  187.    int    i, j, length, width;
  188.    struct tiff_header_struct image_header;
  189.  
  190.    create_file_if_needed(in1_name, out_name, out_image);
  191.  
  192.    read_tiff_image(in1_name, the_image,
  193.                    il1, ie1, ll1, le1);
  194.    read_tiff_image(in2_name, out_image,
  195.                    il2, ie2, ll2, le2);
  196.  
  197.    for(i=0; i<ROWS; i++){
  198.       if ( (i%10) == 0) printf(" %d", i);
  199.       for(j=0; j<COLS; j++){
  200.          if( the_image[i][j] == 0   &&
  201.              out_image[i][j] == 0)
  202.              out_image[i][j] = value;
  203.          else
  204.              out_image[i][j] = 0;
  205.       }  /* ends loop over j */
  206.    }  /* ends loop over i */
  207.  
  208.    write_array_into_tiff_image(out_name, out_image,
  209.                                il3, ie3, ll3, le3);
  210.  
  211. } /* ends nor_image */
  212.  
  213. /*****************************************************/
  214.  
  215. not_image(in_name, out_name, the_image, out_image,
  216.           il, ie, ll, le, value)
  217.    char   in_name[], out_name[];
  218.    int    il, ie, ll, le;
  219.    short  the_image[ROWS][COLS],
  220.           out_image[ROWS][COLS],
  221.           value;
  222. {
  223.    int    i, j, length, width;
  224.    struct tiff_header_struct image_header;
  225.  
  226.    create_file_if_needed(in_name, out_name, out_image);
  227.  
  228.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  229.  
  230.    for(i=0; i<ROWS; i++)
  231.       for(j=0; j<COLS; j++)
  232.          out_image[i][j] = value;
  233.  
  234.    for(i=0; i<ROWS; i++){
  235.       if ( (i%10) == 0) printf(" %d", i);
  236.       for(j=0; j<COLS; j++){
  237.          if(the_image[i][j] == value)
  238.              out_image[i][j] = 0;
  239.       }  /* ends loop over j */
  240.    }  /* ends loop over i */
  241.  
  242.    write_array_into_tiff_image(out_name, out_image,
  243.                                il, ie, ll, le);
  244.  
  245. } /* ends not_image */
  246.  
  247.  
  248.